package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IReturnGoodsService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/returnGoods")
@Controller
public class ReturnGoodsController {

    @Autowired
    private IReturnGoodsService returnGoodsService;


    @RequestMapping("")
    public String view(){

        return "returnGoods";
    }
    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(@ModelAttribute("qo")QueryObject qo){

        PageResult result = returnGoodsService.queryForList(qo);

        return result;
    }

    @RequestMapping("/returnGoods")
    @ResponseBody
    public JsonResult save(Long id){
        JsonResult result = new JsonResult();
        try {
            //JsonArrayFormatVisitor
            returnGoodsService.returnGood(id);

        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("退货失败");
        }
        return result;
    }

}
